﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace B.MES.Orders.Infrastructure
{
    /// <summary>
    /// 仓储层公共接口
    /// </summary>
    /// <typeparam name="T">泛型</typeparam>
    public interface IBaseRepository<T> where T : class,new()
    {
        /// <summary>
        /// 根据主键获取实体对象
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns>实体对象</returns>
        T GetById(object id);

        /// <summary>
        /// 获取所有实体对象列表
        /// </summary>
        /// <returns>实体对象列表</returns>
        List<T> GetAll();

        /// <summary>
        /// 根据条件获取实体对象列表
        /// </summary>
        /// <param name="whereExpression">条件表达式</param>
        /// <returns>符合条件的实体对象列表</returns>
        List<T> GetList(Expression<Func<T, bool>> whereExpression);

        /// <summary>
        /// 插入实体对象到数据库
        /// </summary>
        /// <param name="entity">要插入的实体对象</param>
        /// <returns>插入是否成功</returns>
        bool Insert(T entity);

        /// <summary>
        /// 更新数据库中的实体对象
        /// </summary>
        /// <param name="entity">要更新的实体对象</param>
        /// <returns>更新是否成功</returns>
        bool Update(T entity);

        /// <summary>
        /// 从数据库中删除实体对象
        /// </summary>
        /// <param name="entity">要删除的实体对象</param>
        /// <returns>删除是否成功</returns>
        bool Delete(T entity);
    }
}
